from flask import Blueprint
from flask import redirect
from flask import request
from flask import session
from flask import url_for

admin_blu = Blueprint('admin',__name__,url_prefix='/admin')

from info.modules.admin import views
from info.modules.admin import login


@admin_blu.before_request
def only_admin():
    is_admin = session.get('is_admin')
    login = request.url.endswith(url_for('admin.admin_login'))
    if not is_admin and not login:
        return redirect('/')